<?php
/**
 * Created by JetBrains PhpStorm.
 * User: xjw129xjt
 * Date: 13-8-22
 * Time: 下午3:21
 * To change this template use File | Settings | File Templates.
 */

class InfoAction extends Action
{

    private $_profile_model; // 用户档案模型对象字段

    /**
     * 控制器初始化，实例化用户档案模型对象
     * @return void
     */

    protected function _initialize()
    {

        $this->_profile_model = model('UserProfile');
        // 从数据库读取
        $profile_category_list = $this->_profile_model->getCategoryList();

        $tab_list[] = array('field_key' => 'index', 'field_name' => L('PUBLIC_PROFILESET_INDEX')); // 基本资料
        $tab_list[] = array('field_key' => 'tag', 'field_name' => L('PUBLIC_PROFILE_TAG')); // 基本资料
        $tab_lists = $profile_category_list;

        foreach ($tab_lists as $v) {
            $tab_list[] = $v; // 后台添加的资料配置分类
        }
        $tab_list[] = array('field_key' => 'avatar', 'field_name' => L('PUBLIC_IMAGE_SETTING')); // 头像设置
        $tab_list[] = array('field_key' => 'domain', 'field_name' => L('PUBLIC_DOMAIN_NAME')); // 个性域名
        $tab_list[] = array('field_key' => 'authenticate', 'field_name' => '申请认证'); // 申请认证
        $tab_list_preference[] = array('field_key' => 'privacy', 'field_name' => L('PUBLIC_PRIVACY')); // 隐私设置
        $tab_list_preference[] = array('field_key' => 'notify', 'field_name' => '通知设置'); // 通知设置
        $tab_list_preference[] = array('field_key' => 'blacklist', 'field_name' => '黑名单'); // 黑名单
        $tab_list_security[] = array('field_key' => 'security', 'field_name' => L('PUBLIC_ACCOUNT_SECURITY')); // 帐号安全

        //插件增加菜单
        $tab_list_security[] = array('field_key' => 'bind', 'field_name' => '帐号绑定'); // 帐号绑定

        $this->assign('tab_list', $tab_list);
        $this->assign('tab_list_preference', $tab_list_preference);
        $this->assign('tab_list_security', $tab_list_security);
    }

    public function _pschool()
    {
        $condition['uid'] = $this->mid;
        $condition['education'] = 'primary';
        $school = D('friend_school')->where($condition)->order('entrance_year asc')->select();
        foreach ($school as $key => $val) {
            $school[$key]['stype'] = '小学';
        }
        $this->assign('pschool', $school);
        $y = date('Y', time());
        for ($i = $y; $i >= 1950; $i--) {
            $year[$i] = $i;
        }
        $this->assign('pyear', $year);
        $this->display();
    }

    public function _mschool()
    {
        $condition['uid'] = $this->mid;
        $condition['education'] = 'middle';
        $school = D('friend_school')->where($condition)->order('entrance_year asc')->select();
        foreach ($school as $key => $val) {
            $school[$key]['stype'] =getSchoolType($val['type']);
        }
        $this->assign('mschool', $school);
        $y = date('Y', time());
        for ($i = $y; $i >= 1950; $i--) {
            $year[$i] = $i;
        }
        $this->assign('myear', $year);

        $this->display();
    }

    public function _college()
    {
        $condition['uid'] = $this->mid;
        $condition['education'] = 'college';
        $school = D('friend_school')->where($condition)->order('entrance_year asc')->select();
        foreach ($school as $key => $val) {
            $school[$key]['sname'] = D('Friend')->getSchoolNamebySchoolid($val['school_id']);
            $school[$key]['stype'] = getSchoolType($val['type']);
        }
        $y = date('Y', time());
        for ($i = $y; $i >= 1950; $i--) {
            $year[$i] = $i;
        }
        $area = D('school')->where('pid=0')->order('sort asc')->select();
        $this->assign('school_area', $area);
        /*     dump($friend);
             dump(  $friend[$key]['count'] );*/
        $this->assign('year', $year);
        $this->assign('school', $school);

        $this->display();
    }

    public function basic()
    {
        $area = D('school')->where('pid=0')->order('sort asc')->select();
        $this->assign('school_area', $area);
        $condition['uid'] = $this->mid;
        $user_info = D('friend_info')->where($condition)->select();
        $this->assign('user_info', $user_info['0']);
        $xingzuo = D('friend_xingzuo')->select();

        $this->assign('xingzuo', $xingzuo);


        $this->display();

    }

    public function education()
    {

        $area = D('school')->where('pid=0')->order('sort asc')->select();
        $this->assign('school_area', $area);
        $this->display();

    }

    public function _work()
    {
        $work['0'] = '请选择';
        $work['1'] = 'IT信息技术';
        $work['2'] = '金融';
        $work['3'] = '互联网';
        $work['4'] = '广告传媒';
        $work['5'] = '贸易零售';
        $work['6'] = '交通物流';
        $work['7'] = '房地产';
        $work['8'] = '旅游餐饮';
        $work['9'] = '加工制造业';
        $work['10'] = '石化采掘';
        $work['11'] = '农林牧渔';
        $work['12'] = '社会服务';
        $work['13'] = '医学生物';
        $work['14'] = '教育培训科研';
        $this->assign('work',$work);
        $condition['uid'] = $this->mid;
        $profession =D('friend_info')->where($condition)->select();

        $this->assign('profession',$profession['0']['profession']);

        $career = D('friend_work')->where($condition)->select();
        foreach($career as $k=>$v){
           $career[$k]['start']= explode("/",$v['starttime']);

            $career[$k]['end']= explode("/",$v['endtime']);
            if($v['endtime'] == 'now'){
                $career[$k]['tig'] =1;
            }
        }
        $this->assign('career',$career);
        $y = date('Y', time());
        for ($i = $y; $i >= 1950; $i--) {
            $year[$i] = $i;
        }
        for ($m = 1; $m <=12; $m++) {
            $month[$m] = $m;
        }
        $this->assign('year',$year);
        $this->assign('month',$month);

        $this->display();

    }
    public function work()
    {

        $this->display();

    }

    public function friend_set()
    {
        $marriage_type['0'] = '请选择';
        $marriage_type['1'] = '单身';
        $marriage_type['2'] = '寻找另一半';
        $marriage_type['3'] = '恋爱中';
        $marriage_type['4'] = '已订婚';
        $marriage_type['5'] = '已婚';
        $marriage_type['6'] = '丧偶';
        $marriage_type['7'] = '分居';
        $marriage_type['8'] = '离异';
        $marriage_type['9'] = '一言难尽';
        $this->assign('marriage_type',$marriage_type);

for($i = 0 ;$i<=100;$i++){
    $age[$i]=$i;

}

        for($i = 100 ;$i<=250;$i++){
            $height[$i]=$i;

        }
        $this->assign('age',$age);
        $this->assign('height',$height);
        $this->display();

    }

    function _school()
    {
        $schools = D('school')->where('pid=' . $_POST['pid'])->order('sort asc')->select();
        // dump($_POST['pid']);exit;
        foreach ($schools as $v) {
            echo '<li><a href="javascript:;" onclick="set_school(' . $v['school_id'] . ',\'' . $v['name'] . '\')">' . $v['name'] . '</a></li>';
        }
    }

    function _school1()
    {
        $schools = D('school')->where('pid=' . $_POST['pid'])->order('sort asc')->select();
        // dump($_POST['pid']);exit;
        foreach ($schools as $v) {
            echo '<li><a href="javascript:;" onclick="set_school1(' . $v['school_id'] . ',\'' . $v['name'] . '\')">' . $v['name'] . '</a></li>';
        }
    }

    function _city()
    {
        $schools = D('area')->where('pid=' . $_POST['pid'])->order('sort asc')->select();
        // dump($_POST['pid']);exit;
        foreach ($schools as $v) {
            echo '<li><a href="javascript:;" onclick="load_area(' . $v['area_id'] . ',\'' . $v['title'] . '\',\'' . $_POST['type'] . '\')">' . $v['title'] . '</a></li>';
        }
    }

    function _area()
    {
        $schools = D('area')->where('pid=' . $_POST['pid'])->order('sort asc')->select();
        // dump($_POST['pid']);exit;
        foreach ($schools as $v) {
            echo '<li><a href="javascript:;" onclick="set_area(' . $v['area_id'] . ',\'' . $v['title'] . '\',\'' . $_POST['type'] . '\')">' . $v['title'] . '</a></li>';
        }
    }

    public function updateInfo()
    {
        $condition['uid'] = $this->mid;
        $check = D('friend_info')->where($condition)->select();
        $info = D('friend_info');

        $data['uid'] = $this->mid;
        $data['name'] = $_POST['uname'];
        $data['now_province'] =checknull($_POST['province_now'], $_POST['old_province_now']);
        $data['now_city'] = checknull($_POST['city_now'], $_POST['old_city_now']);
        $data['now_area'] = checknull($_POST['area_now'], $_POST['old_area_now']);
        $data['home_province'] = checknull($_POST['province_home'], $_POST['old_province_home']);
        $data['home_city'] =checknull($_POST['city_home'], $_POST['old_city_home']);
        $data['home_area'] =checknull($_POST['area_home'], $_POST['old_area_home']);
        $data['birthday'] = $_POST['birthday'];
        $data['sex'] = $_POST['sex'];
        $data['height'] = $_POST['height'];
        $data['weight'] = $_POST['weight'];
        $xid = D('Friend')->getxingzuoid($_POST['xingzuo']);
        $data['xingzuoid'] = $xid;

        $data['xuexing'] = $_POST['xuexing'];
        $data['intro'] = $_POST['intro'];


        if ($check == null) {
            $info->data($data)->add();
        } else {
            $info->where($condition)->save($data);
        }
        $this->success('修改成功！');
    }

    public function editcollege()
    {
        $condition['id'] = $_POST['id'];
        $data['education'] = $_POST['education'];
        $data['type'] = $_POST['type'];

        if ($_POST['school'] == 0) {
            $data['school_name'] = D('Friend')->getSchoolNamebySchoolid($_POST['old_school']);
            $data['school_id'] = $_POST['old_school'];
        } else {
            $data['school_name'] = D('Friend')->getSchoolNamebySchoolid($_POST['school']);
            $data['school_id'] = $_POST['school'];
        }
        $data['entrance_year'] = $_POST['year'];
        $data['institute'] = $_POST['institute'];
        $update = D('friend_school')->where($condition);
        $update->save($data);
        $this->ajaxReturn('');

    }

    public function addcollege()
    {
        $school = D('friend_school');
        $data['education'] = $_POST['education'];
        $data['type'] = $_POST['type'];
        $data['uid'] = $this->mid;
        $data['school_name'] = D('Friend')->getSchoolNamebySchoolid($_POST['school']);
        $data['school_id'] = $_POST['school'];
        $data['entrance_year'] = $_POST['year'];
        $data['institute'] = $_POST['institute'];
        $school->data($data)->add();
        $this->ajaxReturn('');
    }

    public function delcollege()
    {
        $condition['id'] = $_POST['id'];
        $college = D('friend_school');

        $college->where($condition)->delete();
        $this->ajaxReturn('');
    }

    public function editmschool()
{
    $condition['id'] = $_POST['id'];
    $data['education'] = $_POST['education'];
    $data['type'] = $_POST['type'];
    $data['school_name'] = $_POST['school'];
    $data['school_id'] = 0;
    $data['entrance_year'] = $_POST['year'];
    $update = D('friend_school')->where($condition);
    $update->save($data);
    $this->ajaxReturn('');

}

    public function addmschool()
    {
        $school = D('friend_school');
        $data['education'] = $_POST['education'];
        $data['type'] = $_POST['type'];
        $data['uid'] = $this->mid;
        $data['school_name'] = $_POST['school'];
        $data['school_id'] = 0;
        $data['entrance_year'] = $_POST['year'];
        $data['institute'] = 0;
        $school->data($data)->add();
        $this->ajaxReturn('');
    }

    public function editpschool()
    {
        $condition['id'] = $_POST['id'];
        $data['education'] = $_POST['education'];
        $data['type'] = 0;
        $data['school_name'] = $_POST['school'];
        $data['school_id'] = 0;
        $data['entrance_year'] = $_POST['year'];
        $update = D('friend_school')->where($condition);
        $update->save($data);
        $this->ajaxReturn('');

    }

    public function addpschool()
    {
        $school = D('friend_school');
        $data['education'] = $_POST['education'];
        $data['type'] = 0;
        $data['uid'] = $this->mid;
        $data['school_name'] = $_POST['school'];
        $data['school_id'] = 0;
        $data['entrance_year'] = $_POST['year'];
        $data['institute'] = 0;
        $school->data($data)->add();
        $this->ajaxReturn('');
    }
    public function addcompany(){
        $compary = D('friend_work');
        $data['company'] = $_POST['company'];
        $data['starttime'] = $_POST['syear'].'/'.$_POST['smonth'];
        if($_POST['isnow'] == 1){
            $data['endtime']='now';
        }
        else{
        $data['endtime'] =  $_POST['eyear'].'/'.$_POST['emonth'];
    }
        $data['content'] = $_POST['content'];
        $data['uid'] = $this->mid;

        $compary->data($data)->add();
        $this->ajaxReturn('');
    }
    public function editcompany(){
        $condition['id'] = $_POST['id'];
        $data['company'] = $_POST['company'];
        $data['starttime'] = $_POST['syear'].'/'.$_POST['smonth'];
        if($_POST['isnow'] == 1){
            $data['endtime']='now';
        }
        else{
            $data['endtime'] =  $_POST['eyear'].'/'.$_POST['emonth'];
        }
        $data['content'] = $_POST['content'];
        $update = D('friend_work')->where($condition);
        $update->save($data);
        $this->ajaxReturn('');
    }
    public function delcompany()
    {
        $condition['id'] = $_POST['id'];
        $work = D('friend_work');

        $work->where($condition)->delete();
        $this->ajaxReturn('');
    }
    public function changeprofession(){
        $profession=D('friend_info');
        $data['profession']=$_POST['profession'];
        $condition['uid'] = $this->mid;
        $profession->where($condition) ->save($data);
        $this->ajaxReturn('');
    }
}